package com.chapter14.list_;

import java.util.Iterator;
import java.util.LinkedList;

/**
 * @author 宋鑫宇
 * @version 1.0
 * LinedList的增删改查的使用
 */
@SuppressWarnings("all")
public class LinkedListCRUD {
    public static void main(String[] args) {
        LinkedList linkedList = new LinkedList();
        //添加
        linkedList.add(123);
        linkedList.add("456");
        linkedList.add(789);
        System.out.println(linkedList);
        //删除
        linkedList.remove(1);
        System.out.println(linkedList);
        //修改
        linkedList.set(1,456);
        System.out.println(linkedList);
        //得到某个节点的对象
        System.out.println(linkedList.get(1));
        //迭代器查询
        System.out.println("=======迭代器查询==========");
        Iterator iterator = linkedList.iterator();
        while (iterator.hasNext()) {
            Object next =  iterator.next();
            System.out.println(next);
        }
        System.out.println("===========for增强查询=======");
        for (Object o : linkedList) {
            System.out.println(o);
        }
        System.out.println("==========普通for查询========");
        for (int i = 0; i < linkedList.size(); i++) {
            System.out.println(linkedList.get(i));
        }
    }
}
